package com.weayer.service;

import com.weayer.dto.PassengerUser;
import com.weayer.dto.ResponseResult;
import com.weayer.dto.TokenResult;
import com.weayer.remote.ServicePassengerUserClient;
import com.weayer.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description:  Api服务 - 乘客 - 用户service
 * @author: Weayer
 **/
@Service
public class UserService {
    @Autowired
    private ServicePassengerUserClient servicePassengerUserClient;

    public ResponseResult getUserByAccessToken(String refreshToken) {
        // 解析 accessToken，获取手机号
        TokenResult tokenResult = JwtUtils.checkToken(refreshToken);
        String phone = tokenResult.getPhone();

        // 根据手机号查询用户信息
        ResponseResult<PassengerUser> userByPhone = servicePassengerUserClient.getUserInfo(phone);


        return ResponseResult.success(userByPhone.getData());
    }
}
